package com.vlyman.config;

import com.vlyman.interceptor.StaticInterceptor;
import com.vlyman.interceptor.SwaggerInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 类描述：
 *  mvc控制器(配置拦截器)
 * @author chenjs
 * @date 2018/10/14 16:19
 **/
@Slf4j
public class WebMvcConfig implements WebMvcConfigurer{

    @Autowired
    private SwaggerInterceptor swaggerInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("初始化swagger的mvc拦截器");
        registry.addInterceptor(swaggerInterceptor).addPathPatterns("/swagger-ui.html");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/","/static", "/public");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");

        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }
}
